package come.tool.FightingEffect;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;

import come.tool.Fighting.*;
import org.come.Frame.ZhuFrame;
import org.come.bean.PathPoint;
import org.come.until.ScrenceUntil;

import com.tool.tcp.GetTcpPath;
import com.tool.tcp.NewPart;
import com.tool.tcp.SpriteFactory;

/**
 * 
 * @author Administrator
 *
 */
public enum  EffectType {
     
	/**0  none*/
	Null(null),
	/** 1 移动  */
	Move(new MoveEffect()),
	/** 2 动画效果  */
	Attack(new AttackEffect()),
	/** 3 召唤召回闪现处理  */
	Pet(new Pet()),
	/** 4逃跑效果  */
	Escape(new EscapeEffect()),
	/** 5捕捉效果  */
	PetCatch(new PetCatch()),
	/** 6技能移动效果  */
	MoveSkill(new MoveSkillEffect()),
	;
    private Effect action;
	
	private EffectType (Effect action){
		this.action = action;
	}
	public Effect getTarget() {
		return action;
	}
	public static Effect getEffectById(int effectId){
		EffectType[] values = EffectType.values();
		EffectType effectType = values[effectId];
		return effectType.getTarget();
	}
	/** 方向调整 
	 *      71  35
		    53  17*/
	public static int getdir(int dir,int camp){
		if (camp==FightingMixDeal.camp||(camp==1&&FightingMixDeal.camp==-1)) {
          if (dir==7) {
              dir=3;
          } else if (dir==3) {
              dir=7;
          } else if (dir==5) {
              dir=1;
          } else if (dir==1) {
              dir=5;
          }
        }
		return dir;
	}
	/**
	 * 数据显示
	 */
	public static StateProgress getProgress(FightingState State,int path){
		StateProgress progress=new StateProgress();
		progress.setMan(path);
		progress.setData2(State.getStartState());
		progress.setData(State.getProcessState());
		progress.setBuff(State.getBuff());
		if (State.getHp_Change()!=null) {
            progress.setHp_Change(State.getHp_Change().intValue());
        }
		if (State.getMp_Change()!=null) {
            progress.setMp_Change(State.getMp_Change().intValue());
        }
		if (State.getYq_c()!=null) {
            progress.setYq_Change(State.getYq_c().intValue());
        }
		if (State.getNq_c()!=null) {
            progress.setNq_Change(State.getNq_c().intValue());
        }
		progress.setAddchixu(State.getEndState_1());
		progress.setDeletechixu(State.getEndState_2());
		progress.setMusic(State.getSkillsy());
		progress.setText(State.getText());
		Fightingimage image=FightingMixDeal.CurrentData.get(path);
		if (State.getUp()!=null&&!"".equals(State.getUp())) {
			String[] vs=State.getUp().split("\\|");
			for (int i = 0; i < vs.length; i++) {
				if (vs[i].startsWith("HP")) {
					image.getFightingManData().setHp_Total(Integer.parseInt(vs[i].split("=")[1]));
				}else if (vs[i].startsWith("MP")) {
					image.getFightingManData().setMp_Total(Integer.parseInt(vs[i].split("=")[1]));
				}
			}
		}
		if (State.getSkin()!=null&&!"".equals(State.getSkin())) {
			image.getFightingManData().setModel(State.getSkin());
			NewPart part=image.getFightingManData().getPart();
			if (image.getFightingManData().getHp_Current()<=0) {part.setAct(8);}
			else {part.setAct(7);}
			image.setPart(part);
		}
        if (State.getSkillskin()!=null&&!"4000".equals(State.getSkillskin())) {
        	SkillSpell skill=new SkillSpell();
        	String skin=State.getSkillskin();
        	int skinID=0;
        	try {
        		if (skin.charAt(0)>=KeyEvent.VK_0&&skin.charAt(0)<=KeyEvent.VK_9) {
        			skinID=Integer.parseInt(skin);
        		}		
			} catch (Exception e) {
				// TODO: handle exception
			}
        	//法术切换
			if(GetTcpPath.STRTMPXJ!=null) {
				if("1".equals(GetTcpPath.STRTMPXJ)) {//新版法术
					if(GetTcpPath.STRTMP!=null) {
						if("1".equals(GetTcpPath.STRTMP)) {
							if("1005".equals(skin)) {
								skin = "10051";
								skinID = 100511;
							}
							if("1010".equals(skin)) {
								skin = "10101";
								skinID = 101011;
							}
							if("1015".equals(skin)) {
								skin = "10151";
								skinID = 101511;
							}
							if("1020".equals(skin)) {
								skin = "10201";
								skinID = 102011;
							}
							if("1025".equals(skin)) {
								skin = "10251";
								skinID = 102511;
							}
							if("1030".equals(skin)) {
								skin = "10301";
								skinID = 103011;
							}
							if("1035".equals(skin)) {
								skin = "10351";
								skinID = 103511;
							}
							if("1040".equals(skin)) {
								skin = "10401";
								skinID = 104011;
							}
							if("1045".equals(skin)) {
								skin = "10451";
								skinID = 104511;
							}
							if("1050".equals(skin)) {
								skin = "10501";
								skinID = 105011;
							}
							if("1055".equals(skin)) {
								skin = "10551";
								skinID = 105511;
							}
							if("1060".equals(skin)) {
								skin = "10601";
								skinID = 106011;
							}
							if("1065".equals(skin)) {
								skin = "10651";
								skinID = 106511;
							}
							if("1070".equals(skin)) {
								skin = "10701";
								skinID = 107011;
							}
							if("1075".equals(skin)) {
								skin = "10751";
								skinID = 107511;
							}
							if("1080".equals(skin)) {
								skin = "10801";
								skinID = 108011;
							}

							if("1085".equals(skin)) {
								skin = "10851";
								skinID = 108511;
							}
							if("1090".equals(skin)) {
								skin = "10901";
								skinID = 109011;
							}
							if("1095".equals(skin)) {
								skin = "10951";
								skinID = 109511;
							}
							if("1100".equals(skin)) {
								skin = "11001";
								skinID = 110011;
							}

						}
					}

					if (skinID==1830||skinID==1867||(skinID>=3036&&skinID<=3044)) {
						if (State.getCamp()==FightingMixDeal.camp) {
							skill.setX(ScrenceUntil.Screen_x/4*3);
							skill.setDir(1);
						}else {
							skill.setX(ScrenceUntil.Screen_x/4*1);
						}
						skill.setY(ScrenceUntil.Screen_y/2);
						skill.setSkinpath(1);
					}else if (skinID==10751||skinID==10701||skinID==10651||skinID==10352||skinID==10851||
							skinID==10952||skinID==11001||skinID==1234||skinID==1236||skinID==7012||
							//全屏法术切换
							skinID==10051||skinID==10101||skinID==10151||skinID==10201||skinID==10251||
							skinID==10302||skinID==10402||skinID==10451||skinID==10501||
							skinID==10551||skinID==10601||skinID==10802||skinID==10901||
							skinID==11276||skinID==11274||skinID==11280||skinID==11279||skinID==11278||skinID==11270||skinID==11268||
							"捕捉".equals(skin)) {
						if(oldFull(skinID, skill)) {

						}else {
							skill.setX(ScrenceUntil.Screen_x/2);
							skill.setY(ScrenceUntil.Screen_y/2);
							skill.setSkinpath(1);
						}
					}else if (skinID==4001||skinID==4002||skinID==4003||skinID==4004) {
						int dir=EffectType.getdir(3,image.getFightingManData().getCamp());
						NewPart part=SpriteFactory.createPart(skin, -1, 0, null);
						ShadowMode shadowMode=new ShadowMode(part, dir==3?image.getX()+70:image.getX()-70,  dir==3?image.getY()+30:image.getY()-30, null, dir==3?1:0);
						skill.setShadowMode(shadowMode);
					}else  if(skinID==12522||(skinID>=1263&&skinID<=1266)) {//心猿魔威
						skill.setX(image.getX()+70);
						skill.setY(image.getY()+25);
						skill.setSkinpath(0);
						skill.setDir(2);
					}else  if(skinID==1261) {//心猿圣佑自己
						skill.setX(image.getX()+80);
						skill.setY(image.getY()-10);
						skill.setSkinpath(0);
						skill.setDir(2);
					}else  if(skinID==12521) {//心猿圣佑打对面
						skill.setX(image.getX()-70);
						skill.setY(image.getY()-40);
						skill.setSkinpath(0);
						skill.setDir(1);
					}else  if(skinID==12525) {//心猿神通
						skill.setX(image.getX()-70);
						skill.setY(image.getY()-20);
						FightingManData.IS_XY_FS = true;
					}else  if(skinID==12523) {//心猿神通
						skill.setX(image.getX()-20);
						skill.setY(image.getY()-20);
						skill.setSkinpath(0);
						skill.setDir(6);
					}else if(skinID==1296) {
						skill.setX(image.getX());
						skill.setY(image.getY());
						skill.setDir(0);
						Fightingimage image2 = null;
						for (Fightingimage currentDatum : FightingMixDeal.CurrentData) {
							if(currentDatum.getFightingManData().getCamp() == 0 && currentDatum.getFightingManData().getMan() == State.getSglxTag()){
								image2 = currentDatum;
								break;
							}
						}

						if(image2 != null){
							String s = FightingMove2.calculateRelativePosition(image.getX(), image.getY(), image2.getX(), image2.getY());

							if(s.equals("上右")){
								skill.setX(image.getX()-20);
								skill.setY(image.getY()-60);
								skill.setDir(11);
							}else if(s.equals("下左") || s.equals("上左")){
								if(s.equals("下左")){
									skill.setDir(1);
								}else{
									skill.setX(image.getX()-120);
									skill.setY(image.getY()-90);
									skill.setDir(0);
								}

							}else if(s.equals("下右")){
								if(State.getMan() == 2){
									skill.setDir(1);
								}else{
									skill.setDir(3);
								}

							}

							//system.out.println("方向 = "+s);
						}
					}else if (skinID==1298) {
						PathPoint[] ssss=MoveEffect.move2(State.getEndState());
						List<PathPoint> lists=new ArrayList<>();
						lists.add(ssss[0]);
						lists.add(ssss[1]);
						int dir=111;
						NewPart part=null;
						part=SpriteFactory.createPart(State.getSkillskin(), -1, 0, null);
						ShadowMode shadowMode=new ShadowMode(part,ssss[0].getX(),ssss[0].getY(), lists,dir);
						skill.setShadowMode(shadowMode);
						progress.setSpell(skill);
						progress.setMan(Integer.parseInt(State.getEndState().split("\\|")[3]));
						progress.setType(0);
						return progress;
					}else {
						skill.setX(image.getX());
						skill.setY(image.getY());
						skill.setSkinpath(0);
					}

					skill.setSkillid(GetTcpPath.getSkillTcp(skin));
					progress.setSpell(skill);

				}else {//旧版法术
					//法术切换
					if(GetTcpPath.STRTMP!=null) {
						if("1".equals(GetTcpPath.STRTMP)) {
							if("1005".equals(skin)) {
								skin = "10051";
								skinID = 10051;
							}
							if("1010".equals(skin)) {
								skin = "10101";
								skinID = 10101;
							}
							if("1015".equals(skin)) {
								skin = "10151";
								skinID = 10151;
							}
							if("1020".equals(skin)) {
								skin = "10201";
								skinID = 10201;
							}
							if("1025".equals(skin)) {
								skin = "10251";
								skinID = 10251;
							}
							if("1030".equals(skin)) {
								skin = "10301";
								skinID = 10301;
							}
							if("1035".equals(skin)) {
								skin = "10351";
								skinID = 10351;
							}
							if("1040".equals(skin)) {
								skin = "10401";
								skinID = 10401;
							}
							if("1045".equals(skin)) {
								skin = "10451";
								skinID = 10451;
							}
							if("1050".equals(skin)) {
								skin = "10501";
								skinID = 10501;
							}
							if("1055".equals(skin)) {
								skin = "10551";
								skinID = 10551;
							}
							if("1060".equals(skin)) {
								skin = "10601";
								skinID = 10601;
							}
							if("1065".equals(skin)) {
								skin = "10651";
								skinID = 10651;
							}
							if("1070".equals(skin)) {
								skin = "10701";
								skinID = 10701;
							}
							if("1075".equals(skin)) {
								skin = "10751";
								skinID = 10751;
							}
							if("1080".equals(skin)) {
								skin = "10801";
								skinID = 10801;
							}
						}
					}

					if (skinID==1830||skinID==1867||skinID==1090||(skinID>=3036&&skinID<=3044)) {
						if (State.getCamp()==FightingMixDeal.camp) {
							skill.setX(ScrenceUntil.Screen_x/4*3);
							skill.setDir(1);
						}else {
							skill.setX(ScrenceUntil.Screen_x/4*1);
						}
						skill.setY(ScrenceUntil.Screen_y/2);
						skill.setSkinpath(1);
					}else if (skinID==1075||skinID==1070||skinID==1065||skinID==1035||skinID==1085||
							skinID==1095||skinID==1100||skinID==1234||skinID==1236||skinID==7012||
							//全屏法术切换
							skinID==1005||skinID==1010||skinID==1015||skinID==1020||skinID==1025||
							skinID==1030||skinID==1035||skinID==1040||skinID==1045||skinID==1050||
							skinID==1055||skinID==1060||skinID==1065||skinID==1070||skinID==1075||skinID==1080||
							skinID==11276||skinID==11274||skinID==11280||skinID==11279||skinID==11278||skinID==11270||skinID==11268||
							"捕捉".equals(skin)) {
						if(oldFull(skinID, skill)) {

						}else {
							skill.setX(ScrenceUntil.Screen_x/2);
							skill.setY(ScrenceUntil.Screen_y/2);
							skill.setSkinpath(1);
						}
					}else if (skinID==4001||skinID==4002||skinID==4003||skinID==4004) {
						int dir=EffectType.getdir(3,image.getFightingManData().getCamp());
						NewPart part=SpriteFactory.createPart(skin, -1, 0, null);
						ShadowMode shadowMode=new ShadowMode(part, dir==3?image.getX()+70:image.getX()-70,  dir==3?image.getY()+30:image.getY()-30, null, dir==3?1:0);
						skill.setShadowMode(shadowMode);
					}else  if(skinID==12522||(skinID>=1263&&skinID<=1266)) {//心猿魔威
						skill.setX(image.getX()+70);
						skill.setY(image.getY()+25);
						skill.setSkinpath(0);
						skill.setDir(2);
					}else  if(skinID==1261) {//心猿圣佑自己
						skill.setX(image.getX()+80);
						skill.setY(image.getY()-10);
						skill.setSkinpath(0);
						skill.setDir(2);
					}else  if(skinID==12521) {//心猿圣佑打对面
						skill.setX(image.getX()-70);
						skill.setY(image.getY()-40);
						skill.setSkinpath(0);
						skill.setDir(1);
					}else  if(skinID==12525) {//心猿神通
						skill.setX(image.getX()-70);
						skill.setY(image.getY()-20);
						FightingManData.IS_XY_FS = true;
					}else  if(skinID==12523) {//心猿神通
						skill.setX(image.getX()-20);
						skill.setY(image.getY()-20);
						skill.setSkinpath(0);
						skill.setDir(2);
					}else if(skinID==1296) {
						skill.setX(image.getX());
						skill.setY(image.getY());
						skill.setDir(0);
						Fightingimage image2 = null;
						for (Fightingimage currentDatum : FightingMixDeal.CurrentData) {
							if(currentDatum.getFightingManData().getCamp() == 0 && currentDatum.getFightingManData().getMan() == State.getSglxTag()){
								image2 = currentDatum;
								break;
							}
						}

						if(image2 != null){
							String s = FightingMove2.calculateRelativePosition(image.getX(), image.getY(), image2.getX(), image2.getY());

							if(s.equals("上右")){
								skill.setX(image.getX()-20);
								skill.setY(image.getY()-60);
								skill.setDir(11);
							}else if(s.equals("下左") || s.equals("上左")){
								if(s.equals("下左")){
									skill.setDir(1);
								}else{
									skill.setX(image.getX()-120);
									skill.setY(image.getY()-90);
									skill.setDir(0);
								}

							}else if(s.equals("下右")){
								if(State.getMan() == 2){
									skill.setDir(1);
								}else{
									skill.setDir(3);
								}

							}

							//system.out.println("方向 = "+s);
						}
					}else if (skinID==1298) {
						PathPoint[] ssss=MoveEffect.move2(State.getEndState());
						List<PathPoint> lists=new ArrayList<>();
						lists.add(ssss[0]);
						lists.add(ssss[1]);
						int dir=111;
						NewPart part=null;
						part=SpriteFactory.createPart(State.getSkillskin(), -1, 0, null);
						ShadowMode shadowMode=new ShadowMode(part,ssss[0].getX(),ssss[0].getY(), lists,dir);
						skill.setShadowMode(shadowMode);
						progress.setSpell(skill);
						progress.setMan(Integer.parseInt(State.getEndState().split("\\|")[3]));
						progress.setType(0);
						return progress;
					}else {
						skill.setX(image.getX());
						skill.setY(image.getY());
						skill.setSkinpath(0);
					}
				}

				skill.setSkillid(GetTcpPath.getSkillTcp(skin));
				progress.setSpell(skill);

			}
		}
		if (State.getMsg()!=null&&State.getCamp()==FightingMixDeal.camp&&FightingMixDeal.myman()==State.getMan()) {
			ZhuFrame.getZhuJpanel().addPrompt2(State.getMsg());
		}
		return progress;	
	}


	
	 private static boolean oldFull(int skinID, SkillSpell skill) {
		 boolean fal = false;


		 if(GetTcpPath.STRTMPXJ!=null) {
			 if("1".equals(GetTcpPath.STRTMPXJ)) {//新版法术

	    if (1050 == skinID) {
	    	fal = true;
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	    }
	    if (1055 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1045 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1015 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1010 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1005 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1020 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1030 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1040 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1025 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
	    if (1035 == skinID) {
	      skill.setX(ScrenceUntil.Screen_x / 2);
	      skill.setY(ScrenceUntil.Screen_y / 2);
	      fal = true;
	    }
		}
	}else {//旧版法术
			 if (1050 == skinID) {
				 fal = true;
				 skill.setX(ScrenceUntil.Screen_x / 2 - 160);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 110);
			 }
			 if (1055 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2);
				 skill.setY(ScrenceUntil.Screen_y / 2);
				 fal = true;
			 }
			 if (1045 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 145);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 120);
				 fal = true;
			 }
			 if (1015 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 110);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 140);
				 fal = true;
			 }
			 if (1010 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 110);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 100);
				 fal = true;
			 }
			 if (1005 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2);
				 skill.setY(ScrenceUntil.Screen_y / 2);
				 fal = true;
			 }
			 if (1020 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 170);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 140);
				 fal = true;
			 }
			 if (1030 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 125);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 115);
				 fal = true;
			 }
			 if (1040 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 165);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 130);
				 fal = true;
			 }
			 if (1025 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2 - 160);
				 skill.setY(ScrenceUntil.Screen_y / 2 - 110);
				 fal = true;
			 }
			 if (1035 == skinID) {
				 skill.setX(ScrenceUntil.Screen_x / 2);
				 skill.setY(ScrenceUntil.Screen_y / 2);
				 fal = true;
			 }

		 }

		return fal;
	  }
}
